package com.zhny.view;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.util.logging.Logger;

/**
 * @Author 侯俊杰
 * @Date 2017/11/8
 * @Time 19:42
 **/
public class MainJTabbedPane
{
    public JTabbedPane tabbedPane;
    public Logger logger = Logger.getLogger("MainJTabbedPane");
    public  JTabbedPane getMyTabbedPane()
    {

        tabbedPane = new JTabbedPane();
        tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
        tabbedPane.addChangeListener(new ChangeListener()
        {
            public void stateChanged(ChangeEvent e)
            {
                //获得被选中选项卡的索引
                int selectedIndex = tabbedPane.getSelectedIndex();
                //获得指定索引的选项卡标签
                String title = tabbedPane.getTitleAt(selectedIndex);

                logger.info("切换到了"+title+"标签");
            }
        });

        Component panelTelemetering = new TelemeteringJPanel().getMyTelemeteringJPanel();
        //addTab中的第二个参数为组件，这个组件替换为我们的JPanel组件
        tabbedPane.addTab("遥 测",panelTelemetering);

        JLabel tabLabelB = new JLabel("系统正在升级，其他功能还未添加",SwingConstants.CENTER);
        tabbedPane.addTab("待扩展",tabLabelB);


        tabbedPane.setToolTipTextAt(1,"系统正在升级，其他功能还未添加");
        tabbedPane.setEnabledAt(1,false);
        return tabbedPane;
    }
}
